package com.flycent.hqhs.ui;

import net.tsz.afinal.FinalActivity;
import net.tsz.afinal.annotation.view.ViewInject;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

import com.flycent.hqhs.App;
import com.flycent.hqhs.R;
import com.flycent.hqhs.http.WebClient;
import com.flycent.hqhs.http.WebException;
import com.flycent.hqhs.ui.view.SimpleTitleBar;

/**
 * 反馈
 * @author fbl
 */
public class FeedBackActivity extends BackableTitleBarActivity{
	@ViewInject(id = R.id.feedbackEdit) EditText mFeedBackEditText; 
	@ViewInject(id = R.id.feedback_contact) EditText mContactEditText; 

	@Override
	protected void onCreate(Bundle savedInstance) {
		super.onCreate(savedInstance);
		setContentView(R.layout.activity_feedback);
		FinalActivity.initInjectedView(this);

	}

	@Override
	protected void onTitleBarCreated(SimpleTitleBar titleBar) {
		super.onTitleBarCreated(titleBar);
		titleBar.setTitle(R.string.title_feedback);

		titleBar.setRightButtonText(getString(R.string.title_right_submit_text));

		titleBar.setOnRightButtonClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				if(invalidateText(mFeedBackEditText,R.string.please_input_feedback_text)
						|| invalidateText(mContactEditText, R.string.please_input_feedback_contact)){
					return;

				}
				doRequest(getText(mFeedBackEditText),getText(mContactEditText));

			}

			private void doRequest(final String str1,final String str2) {
				showLoadingDialog("");
				new Thread(){
					public void run() {
						try {
							WebClient.getInstance(FeedBackActivity.this).submit(str1, str2);
							mHandler.sendEmptyMessage(0);
						} catch (WebException e) {
							dismissLoadingDialog();
							e.printStackTrace();
						}
					};
				}.start();


			}
		});
	}

	@SuppressLint("HandlerLeak") 
	final Handler mHandler = new Handler(){
		public void dispatchMessage(android.os.Message msg) {
			switch (msg.what) {
			case 0:
				dismissLoadingDialog();
				App.showShortToast("反馈成功");
				FeedBackActivity.this.finish();
				break;

			default:
				break;
			}
		};
	};


}
